import InterbankTransferData from './data';
import { POST, } from '../../../commons/utils/request';

export default class InterbankTransferBusiness {
  // 汇出 提交接口参数构造
  static requestDataFordeaOutSubmit(bizData) {
    const res = {
      accNo: bizData.payerInfo.accNo || "", /** 付款账户 string */
      currencyType: bizData.payerInfo.currencyType || 0, /** 币种 int */
      accBalance: bizData.payerInfo.accBalance || "", /** 账户余额， string */
      dealAmount: bizData.payerInfo.dealAmount || 0, /** 汇款金融 number double */
      remark: bizData.payerInfo.remark || "", /** 汇款附言 string */
      useType: bizData.payerInfo.useType || 0, /** 汇款用途 int */
      receiverType: bizData.payeeInfo.receiverType || 1, /** 收款方类型 1 个人 2 企业 int */
      receiverName: bizData.payeeInfo.receiverName || "", /** 收款方姓名 string */
      receiverBankCard: bizData.payeeInfo.receiverBankCard || "", /** 收款人账号 */
      receiverCountryCode: bizData.payeeInfo.receiverCountryCode || "", /** 收款人国家地区 string */
      receiverAddress: bizData.payeeInfo.receiverAddress || "", /** 收款人地址 string */
      receiverBankName: bizData.payeeInfo.receiverBankName || "", /** 收款人银行名称 string */
      receiverBankSwiftNo: bizData.payeeInfo.receiverBankSwiftNo || "", /** 收款人银行 swfit号 */
      receiverBankAddress: bizData.payeeInfo.receiverBankAddress || "", /** 收款人银行地址 string */
      receiverBankCountryCode: bizData.payeeInfo.receiverCountryCode || "", /** 收款行国家地区 sting */
      mobileRemark: bizData.payeeInfo.mobileRemark || "", /** 收款人短信通知 */
      ifHasAgent: bizData.payeeInfo.ifHasAgent == true ? 1 : 0, /** 是否有代理行 int */
      chargeFee: bizData.payerInfo.chargeFee || "",
      chargeType: bizData.payerInfo.chargeType || 1,
    };
    if (res.ifHasAgent == 1) {
      res.agentBankSwiftNo = bizData.payeeInfo.agentBankSwiftNo || '';
      res.agentBankAddress = bizData.payeeInfo.agentBankAddress || '';
      res.agentBankCountryCode = bizData.payeeInfo.agentBankCountryCode || '';
      res.agentBankName = bizData.payeeInfo.agentBankName || '';
    }
    console.log('lth : commit res is ', res);
    return res;
  }
  static doCommit(bizData, success, fail) {
    POST('http://120.48.109.211:8088//deal/deaOutSubmit',
      JSON.stringify(InterbankTransferBusiness.requestDataFordeaOutSubmit(bizData)))
      .then(resp => {
        if (resp && resp.code == 0) {
          success && success(resp.data);
        } else {
          fail && fail(resp);
        }
      });
  }

  static fetchTradeEnum(success, fail) {
    POST('http://120.48.109.211:8088//deal/dealEnums', '').then(resp => {
      console.log('resp dealEnums is ', resp);
      if (resp && resp.data) {
        success && success(resp.data);
      } else {
        fail && fail(resp);
      }
    });
  }

  static fetchPayerInfo(success, fail) {
    POST('http://120.48.109.211:8088/deal/dealOutFromAccountInfo', '').then(resp => {
      if (resp && resp.data) {
        success && success(resp.data);
      } else {
        fail && fail(resp);
      }
    });
  }

  static chargeFeeCal(dealAmount, success, fail) {
    POST('http://120.48.109.211:8088/deal/chargeFeeCal', JSON.stringify({
      chargeType: 1,
      dealAmount,
    })).then(resp => {
      if (resp && resp.data) {
        success && success(resp.data);
      } else {
        fail && fail(resp);
      }
    });
  }
}
